
var treeDataC;//树状图数据

var initScaleW = 320;//初始屏幕宽
var initScaleH = 508;//初始屏幕高
var initTopW = initScaleW;//初始上部宽
var initTopH = 350;//初始上部高
var initFooterW = initScaleW;
var initFooterH = initScaleH - initTopH;//初始下部宽
var initFooterH;//初始下部高
var windowW;
var windowH;
//设置屏幕比例
function setScale(){
	windowW = 0;
	windowH = 0;
	initTopH = 350;
	windowW = window.innerWidth;//屏幕宽
	windowH = document.documentElement.clientHeight; 
	windowH = windowH > 0 ? windowH : 567;//屏幕高
	
//	alert(document.documentElement.clientHeight + "---windowH:" +  window.innerHeight);
//	alert(windowW + "---" + windowH);
//	 alert("windowW:" + windowW + "---windowH:" + windowH);
	var canvasScale = 2;//画布比例
	
	var top = document.getElementById("mainTopC");
	var footer = document.getElementById("mainFooterC");
	
	if(windowH < initScaleH){
		//小屏幕  短屏
		windowH = initScaleH;
	}
//	alert(initTopH);
	initTopH = parseInt(windowH * initTopH / initScaleH);
//	alert(initTopH);
	initFooterH = windowH - initTopH;
	initFooterW = windowW;
//	alert("initTopH:" + initTopH + "---windowH:" + windowH + "---initFooterH:" + initFooterH);
	// if(windowW > windowH){
	// 	//横屏
	// 	initTopH = 	
	// }

	//设置上下部分比例
	top.style.height = initTopH + "px";
	// console.log("initTopH:" + initTopH);
	setScaleTop(initTopH,windowW);
	footer.style.height = initFooterH + "px";

	//树状图
	// treeDataC = verticalsDay[0];
	// treeDataC = sleepDate;
	// console.log(treeDataC.treeData.length);
	
	canvasW = initFooterW * canvasScale;
	canvasH = initFooterH * canvasScale;
//	alert(canvasW + "---canvas--" + canvasH);
	// console.log(canvasW + "---" + canvasH);
	//初始化画布
	// initCanvasBg(canvasW, canvasH, bgColor);

	drawTreeC(canvasW, canvasH, initData,bgColor,0);

}

//设置头部图片位置
function setScaleTopHeaderImg(){
	//左上图片位置
	var mainLeftBtnImgC =  document.getElementById("mainTopLeftBtnC");
	mainLeftBtnImgC.style.width = parseInt(setTopHH * 24 / 47);
	mainLeftBtnImgC.style.marginTop =  setTopHH * 16 / 47 + "px";
}
var imgBgWidth;
//设置圆环位置
function setScaleTopCenterRing(){
	//圆环比例以及位置

	var ringTitleTopH = 105 / 160;
	var ringDefaultTopH = 70 / 160;
	var ringTitleTop = document.getElementById("ringTitle");
	var ringDefaultTop = document.getElementById("ring_default");
	var ringDefaultNull = document.getElementById("ring_default_null");
//	var ringSleeplevel = document.getElementById("sleep_level_value");
	
//	ringTitleTop.style.width = imgBgWidth + "px";

	ringTitleTop.style.top =  setTopCH * ringTitleTopH + "px";
//	ringDefaultTop.style.width = setTopCW + "px" ;
	ringDefaultTop.style.top = setTopCH * ringDefaultTopH + "px";
//	ringDefaultNull.style.width = setTopCW + "px";
	ringDefaultNull.style.top = setTopCH * ringDefaultTopH + "px";
//	ringSleeplevel.style.width = imgBgWidth + "px";
}

//设置上下一页位置
function setScaleTopCenterLR(){
	//左右位置
	var mainPreNextH = document.getElementById("mainNextImgDC").offsetHeight;
	mainPreNextH = mainPreNextH ? mainPreNextH : 40;
	document.getElementById("mainPreImgDC").style.marginTop = setTopCH / 2 - mainPreNextH / 2 + "px";
	document.getElementById("mainNextImgDC").style.marginTop = setTopCH / 2 - mainPreNextH / 2 + "px";
}

//设置底部文字比例
function setScaleFooter(){
	// console.log(height - setTopCH - setTopHH);
	//描述文字比例位置
	var mainTopFooterCH = document.getElementById("mainTopFooterC");
	var sleepText = document.getElementById("sleepText");
	sleepText.style.marginTop = setTopFH * 22 / 121 + "px";
	sleepText.style.marginBottom = setTopFH * 10 / 121 + "px";
	mainTopFooterCH.style.height = setTopFH -  setTopFH * 22 / 121 + "px";
	
	setTopFooterCoo(0);
}

//设置上部分详细比例
function setScaleTopSleep(){

	setScaleTopHeaderImg();
	
	setScaleTopCenterRing();
	
	setScaleTopCenterLR();
	
	setScaleFooter();
	
	
}
// var imgBgW;
var setTopHH;
var setTopCH;
var setTopCW;
var setTopFH;
//设置上部分内容比例
function setScaleTop(height,width){
	// console.log(width);
	//头部比例
	// var setTopHH = setScaleTopHeader(height,width);

	var mainTopHeaderH = 50 / 350;//头部信息高度
	var mainTopH =  document.getElementById("mainTopHeaerC");
	var mainLeftH = document.getElementById("mainLeftBtnC");
	var maincenterH = document.getElementById("mainCenterTextC");
	var mainRightH = document.getElementById("mainRightBtnC");
	setTopHH = parseInt(height * mainTopHeaderH) ;
	// console.log("setTopHH:" + setTopHH);
	mainTopH.style.height = setTopHH + "px";
	mainTopH.style.lineHeight = setTopHH + "px";
	mainLeftH.style.height = setTopHH + "px";
	maincenterH.style.height = setTopHH + "px";
	mainRightH.style.height = setTopHH + "px";
	mainRightH.style.lineHeight = setTopHH + 3 + "px";


	//圆环 + 左右 比例
	// var setTopCH = setScaleTopCenter(height,width);

	var mainTopCenterH = 160 / 350;//圆环高度比例
	var mainTopCenterW = 160 / 320;//圆环宽度比例
	var mainCenterH = document.getElementById("mainTopCenterC");
	var mainCenterRingCW = document.getElementById("mainCenterRingC");
	var mainPreH = document.getElementById("mainPreviousC");
	var mainNextH = document.getElementById("mainNextC");
	setTopCH = parseInt(height * mainTopCenterH);
	setTopCW = parseInt(width * mainTopCenterW);
//	 console.log("setTopCH:" + setTopCH);
	mainCenterH.style.height = setTopCH + "px";
	mainCenterRingCW.style.height = setTopCH + "px";
	mainPreH.style.height = setTopCH + "px";
	mainNextH.style.height = setTopCH + "px";
		
	var mainRingW = document.getElementById("mainRingImgC");
	if(windowW > windowH){
		mainRingW.style.width = setTopCH + "px";
		// mainRingW.style.marginTop = setTopCH / 2 + "px";
		imgBgWidth = setTopCH;
//		console.log("11111");
	}else{
		mainRingW.style.width = setTopCH + "px";
//		mainRingW.style.marginTop = setTopCH / 2 - setTopCW / 2 + "px";
		imgBgWidth = setTopCH;
//		console.log("22222");
		if(windowH / windowW < 1.5){
			mainRingW.style.width = setTopCH + "px";
//			mainRingW.style.marginTop = setTopCH / 2 - setTopCW / 2 + "px";
			imgBgWidth = setTopCH;
//			console.log("33333");
		}else{
			mainRingW.style.width = setTopCW + "px";
			mainRingW.style.marginTop = setTopCH / 2 - setTopCW / 2 + "px";
			imgBgWidth = setTopCW;
//			console.log("44444");
		}
	}

	// imgBgW = mainRingW.style.width;

	//底部文字
	// setScaleFooter(height,width,height - setTopCH - setTopHH);

	setTopFH = height - setTopCH - setTopHH;
	// console.log( "setTopFH:" + setTopFH + "---height:" + height + "setTopCH:" + setTopCH +"---setTopHH:" + setTopHH)
	var mainTopFooterCH = document.getElementById("mainTopFooterC");
	mainTopFooterCH.style.height = setTopFH + "px";



	
}

//初始化画布背景
function initCanvasBg(width,height,bgColor){
	var canvas = document.getElementById("canvasC");
	canvas.width = width;
	canvas.height = height;	
	var ctx = canvas.getContext("2d");

	var shadowBlur = 1;//模糊等级
	//绘制背景色
	ctx.beginPath();
	ctx.shadowBlur = shadowBlur;
	ctx.fillStyle = bgColor;
	ctx.closePath();
	ctx.fillRect(0, 0, width, height);

	// //无数据的时候
	// ctx.beginPath();
	// ctx.font = "bolder 32px Helvetica";
	// ctx.fillStyle = "#959595";
	// ctx.textBaseline = "middle";
	// ctx.textAlign = "center";
	// ctx.fillText("暂无数据", width / 2, height / 2);
	// ctx.closePath();	

}


var canvasW;//画布宽度  初始320
var canvasH;//画布高度  初始158

var bgColor = "#e6e9ed";
/**
 * 绘制树状图
 * width 画布宽
 * height 画布高
 * data 画布数据
 * lineColor 横线颜色
 * rowColor 树状条颜色	
 */
function drawTreeC(width,height,data,bgColor,type){
//	alert("v3...");
	var canvas = document.getElementById("canvasC");
	canvas.height = height;
	canvas.width = width;
	var ctx = canvas.getContext("2d");
	// console.log("height:" + height + "---width:" + width);
	var initCanvasScaleW = 320;//初始画布宽度
	var initCanvasScaleH = 158;//初始画布高度
	var shadowBlur = 1;//模糊等级
	var treeData = data;
	//绘制背景色
	ctx.beginPath();
	ctx.shadowBlur = shadowBlur;
	ctx.fillStyle = bgColor;
	ctx.closePath();
	ctx.fillRect(0, 0, width, height);

	if(type == 0){
		//天树状图
		drawDayTable(width,height,initCanvasScaleW,initCanvasScaleH,ctx,treeData);

	}else{
		//周树状图
		drawWeekTable(width,height,initCanvasScaleW,initCanvasScaleH,ctx,treeData);
	}

}
//绘制周的树状图
function drawWeekTable(width,height,initCanvasScaleW,initCanvasScaleH,ctx,data){

	var lineHeight = 25;//线条之间行高
	var bottomHeight = 30;//底部文字所占高度
	var topTitleHeight = 51;//头部文字所占高度
	var horLineWidth = 1;//水平线条宽度
	var horLienLength = 4;//绘制多少条水平线
	var verLineWidth = 5;//树状条的宽度
	var lineColor = "#a3a4a6";//线条颜色
	var rowColor = "#e79012";//树状条颜色
	var lineOneY;//第一条线Y轴
	var lineOneX;//第一条线X轴
	
	var treeTitle = document.getElementById("dayOrWeek").innerHTML;
	
	var xLabels = data.xLabels.split(",");
	var yValues = data.yValues.split(",");
	
	//数据长度 确定绘制多少树状条
//	var yLen = data.xLabels.length;
//	var xLen = data.yLabels.length;
	
	//数据长度 确定绘制多少树状条
	var yLen = xLabels.length;
	var xLen = yValues.length;

	var checkTreeCount = 0;//检查树状条数据是否全部为空


	//设置适应各种屏幕大小各数据的比例
	lineHeight = height * lineHeight / initCanvasScaleH;
	bottomHeight = height * bottomHeight / initCanvasScaleH;
	verLineWidth = width * verLineWidth / initCanvasScaleW;
	topTitleHeight = height * topTitleHeight / initCanvasScaleH;
	lineOneY = height - bottomHeight;
	lineOneX = width * 0.07;
	var lineLength = width - lineOneX * 2;//横线条长度

	
	//绘制横向线条 + 左边文字
	var yLabels = data.yLabels ? data.yLabels.split(",") : new Array();
	for(var i = 0; i < yLabels.length; i++){
		ctx.beginPath();
		ctx.shadowBlur = 0;
		ctx.strokeStyle = lineColor;
		ctx.lineWidth = horLineWidth;
		
		//线条
		ctx.moveTo(lineOneX, lineOneY - i * (lineHeight + horLineWidth));
		ctx.lineTo(width - lineOneX, lineOneY - i * (lineHeight + horLineWidth));

		
		ctx.stroke();
		
		
		ctx.textBaseline="middle";
		ctx.font = "24px Helvetica";
		ctx.fillStyle = lineColor;
		if( yLabels[i] * 1 > 9){
			ctx.fillText(yLabels[i] ,lineOneX - lineOneX / 2 - ctx.measureText(i * 4).width / 2, lineOneY - i * (lineHeight + horLineWidth));
		}else{
			ctx.fillText(yLabels[i] ,lineOneX - lineOneX / 2 - ctx.measureText(i * 4).width / 2, lineOneY - i * (lineHeight + horLineWidth));
		}
		ctx.closePath();
	}

	ctx.beginPath();
	ctx.fillStyle = lineColor;
	ctx.font = "900  26px Helvetica";
	//绘制表格头部文字
	if(treeTitle == "周"){
		ctx.fillText("时长（小时）", lineOneX - lineOneX / 2, topTitleHeight / 2);
	}else{
		ctx.fillText("翻身强度", lineOneX - lineOneX / 2, topTitleHeight / 2);
	}
	ctx.closePath();

	// var lineLength = width - lineOneX * 2;//横线条长度
	var btTextWidth = lineLength /  yLen;//底部文字宽度
	// console.log(lineLength +" ----" +btTextWidth)
	var horLineHeight = (horLienLength - 1) * lineHeight + (horLienLength - 1) * horLineWidth;//树状条高度范围
	var bfb;//百分比
	var verXStart;//树状条开始X轴
	var verYStart = lineOneY;//树状条开始Y轴
	var verYend;//树状条Y轴结束
	ctx.beginPath();
	ctx.strokeStyle = rowColor;
	ctx.lineWidth = verLineWidth;
	ctx.textAlign="center";
	ctx.font = "bolder 24px Helvetica";

	
	//绘制底部文字 + 树状条
//	for(var i = 0; i < data.yLabels.length; i++){
//		alert(data.yLabels[i]);
//	}
//	alert(xLen);
	//alert(data.yLabels[xLen-1]=="24");
	
	for(var i = 0; i < yLen; i++){
		// console.log(treeTitle)
		verXStart = lineOneX + (btTextWidth / 2);

		if(treeTitle == "周"){
			if(data.yLabels[xLen-1]=="24"){
				bfb = horLineHeight / 12/2;
			}else{
				bfb = horLineHeight / 12;
			}
			verYend = lineOneY - yValues[i] / 60 * bfb
		}else{
			bfb = horLineHeight / 180;
			verYend = lineOneY - yValues[i] * bfb
		}
		
		ctx.moveTo(verXStart + i * btTextWidth, verYStart);
		ctx.lineTo(verXStart + i * btTextWidth, verYend);
		//文字
		if(yLen < 10){
			ctx.fillText(xLabels[i], verXStart + i * btTextWidth, lineOneY + bottomHeight / 2);
			
		}else if (yLen < 14){
			
			if(i % 2 == 1){
				ctx.fillText(xLabels[i], verXStart + i * btTextWidth, lineOneY + bottomHeight / 2);
			}

		}else{
			
			if(i % 3 == 1){
				ctx.fillText(xLabels[i], verXStart + i * btTextWidth, lineOneY + bottomHeight / 2);
			}

		}

		yValues[i] && (checkTreeCount++);
	}
	ctx.closePath();
	ctx.stroke();


	//判断树状条数据是否全部为空	
	if(checkTreeCount == 0){
		ctx.beginPath();
		ctx.font = "bolder 32px Helvetica";
		ctx.fillStyle = "#959595";
		ctx.textBaseline = "middle";
//		ctx.fillText("暂无数据", lineLength / 2 + lineOneX, lineOneY - (lineHeight + horLineWidth) - lineHeight / 2);
		ctx.fillText("亲，是不是忘了上传睡眠数据呢？", lineLength / 2 + lineOneX, lineOneY - (lineHeight + horLineWidth) - lineHeight / 2);
		ctx.closePath();
	}	
	
}

var checkTreeCount = -1;//检查树状条数据是否全部为空
//绘制天的的树状图
function drawDayTable(width,height,initCanvasScaleW,initCanvasScaleH,ctx,treeData){
	// 1 觉醒颜色 2 浅度睡眠颜色 3 深度睡眠颜色 
	var color = ['#e79012', '#7eb4dd', '#3890d3'];
	// 1 提示文字颜色 2底部文字颜色 
	var txtColor = ['#606060', '#a3a4a6'];
	//觉醒高度
	var awakeHeight = 28;
	//浅度高度
	var shallowHeight = 50;
	//深度高度
	var deepHeight = 88;
	//睡眠的图标
	var sleepIcon = document.getElementById("canvasIcon");
	//觉醒线的高度
	var horLineHeight = 120;	
	//底部第一条线Y
	var footerLineY = 23;
	//底部第一条线X
	var footerLineX = width * 0.07;
	
	// //tips第一个圆X轴
	// var ringOneX = 140;
	//提示文字位置
	var tipsY = 15;

	var tipsText = ['觉醒', '浅度睡眠', '深度睡眠'];

	//睡眠总时长 所有树状图的长度
	var treeWidth = treeData.sleepHoursM;
	//树状条长度
//	var treeLen = treeData.yValues.length;
//	var treeType = treeData.xLabels;
//	var data = treeData.yValues;
	var treeType = treeData.xLabels.split(",");
	var data = treeData.yValues.split(",");
	var treeLen = treeData.yValues ? data.length : 0;
	//底部线条长度
	var footerLineLen = width - footerLineX;

	footerLineY = height * footerLineY / initCanvasScaleH;
	awakeHeight = height * awakeHeight / initCanvasScaleH;
	shallowHeight = height * shallowHeight / initCanvasScaleH;
	deepHeight = height * deepHeight / initCanvasScaleH;
	horLineHeight = height * horLineHeight / initCanvasScaleH;
	tipsY = height * tipsY / initCanvasScaleH;


	if(treeData.daySetTsDate){
		treeWidth = (treeData.daySetTwDate.time - treeData.daySetTsDate.time) / (1000 * 60)
	}


	//绘制图标提示
	var tipsOneX = width - footerLineX;//右到左		
	var tipsTextW;//提示文字宽度
	var tipsRingW = 10 * 2;//小圆的宽度
	
	for(var i = 2; i >= 0; i--){
		tipsTextW = ctx.measureText(tipsText[i]).width / 2;
		ctx.beginPath();
		ctx.font = "bold 18px Helvetica";
		ctx.textBaseline = "middle";
		ctx.textAlign = "center";
		ctx.fillStyle = txtColor[0];
		ctx.fillText(tipsText[i], tipsOneX - ctx.measureText(tipsText[i]).width / 2, tipsY);

		ctx.beginPath();
		ctx.fillStyle = color[i];
		ctx.arc(tipsOneX - ctx.measureText(tipsText[i]).width - tipsRingW, tipsY, 10, 0 * Math.PI, 2.0 * Math.PI);
		ctx.closePath();
		ctx.fill();

		tipsOneX = tipsOneX - ctx.measureText(tipsText[i]).width - tipsRingW * 2;
	}

	
	if(treeLen > 0){

		var downTime;
		var upTime;

		if(treeData.daySetTsDate){
			downTime = treeData.daySetTsDate;
			upTime = treeData.daySetTwDate;
		}else{
			downTime = treeData.sleepTime;
			upTime = treeData.getupTime;
		}
		
		//绘制底部的横线
		ctx.beginPath();
		ctx.strokeStyle = txtColor[1];
		ctx.lineWidth = 2 / 3;
		ctx.moveTo(footerLineX, height - footerLineY);
		ctx.lineTo(width - footerLineX, height - footerLineY);
		ctx.closePath();
		ctx.stroke();
		
		
		//绘制底部文字
		ctx.beginPath();
		ctx.fillStyle = txtColor[1];
		ctx.font = "bolder 22px Helvetica";
		ctx.textAlign = "center";
		ctx.textBaseline = "middle";
		ctx.fillText(formatHourM(downTime.hours,downTime.minutes), footerLineX, height - footerLineY / 2);
		ctx.fillText(formatHourM(upTime.hours,upTime.minutes), footerLineLen, height - footerLineY / 2);
		ctx.closePath();

		
		//绘制树状图
		var img = document.getElementById("ring_zzz_icon");
		var rectX = 0;
		var rectW = 0;
		for(var i = 0; i < treeLen; i++){
			if(i > 0){
				rectX += rectW;
			}
			rectW = data[i] / treeWidth * (footerLineLen - footerLineX);

			switch(treeType[i]){

				case '1':
					ctx.beginPath();		
					ctx.fillStyle = color[0];
					ctx.fillRect(footerLineX + rectX, height - footerLineY - awakeHeight, rectW, awakeHeight);
					ctx.closePath();

					if(i == 0){
						//绘制虚线 图标 文字			
						// var sleepH = treeData.sleepTime.hours;
						// var sleepM = treeData.sleepTime.minutes + data[0];

						var sleepH = downTime.hours;
						var sleepM = downTime.minutes + data[0] * 1;	
						if(sleepM >= 60){
							sleepH = (sleepH + 1) < 24 ? (sleepH + 1) : 00;
							sleepM = sleepM % 60;
						}
						drawDottedLine(footerLineX + rectW, height - footerLineY, horLineHeight, formatHourM(sleepH, sleepM),sleepIcon, txtColor[1],ctx);

					}
					
				break;
				case '2':
					ctx.beginPath();		
					ctx.fillStyle = color[1];
					ctx.fillRect(footerLineX + rectX, height - footerLineY - shallowHeight, rectW, shallowHeight);
					ctx.closePath();
				break;
				default:
					ctx.beginPath();		
					ctx.fillStyle = color[2];
					ctx.fillRect(footerLineX + rectX, height - footerLineY - deepHeight, rectW, deepHeight);
					ctx.closePath();
				break;

			}
			// data[i] && (checkTreeCount++);
		}
		
	
	}else{

		if(treeData.memberSetTsDate){

			var downTime;
			var upTime;
			
			if(treeData.daySetTsDate){
				downTime = treeData.daySetTsDate;
				upTime = treeData.daySetTwDate;
			}else{
				downTime = treeData.memberSetTsDate;
				upTime = treeData.memberSetTwDate;
			}


			//绘制底部文字
			ctx.beginPath();
			ctx.fillStyle = txtColor[1];
			ctx.font = "bolder 22px Helvetica";
			ctx.textAlign = "center";
			ctx.textBaseline = "middle";
			ctx.fillText(formatHourM(downTime.hours,downTime.minutes), footerLineX, height - footerLineY / 2);
			ctx.fillText(formatHourM(upTime.hours,upTime.minutes), footerLineLen, height - footerLineY / 2);
			ctx.closePath();

			//绘制底部的横线
			ctx.beginPath();
			ctx.strokeStyle = txtColor[1];
			ctx.lineWidth = 2 / 3;
			ctx.moveTo(footerLineX, height - footerLineY);
			ctx.lineTo(width - footerLineX, height - footerLineY);
			ctx.closePath();
			ctx.stroke();

			//绘制虚线
			var sleepH = treeData.memberSetTsDate.hours;
			var sleepM = treeData.memberSetTsDate.minutes + 20;

			if(sleepM >= 60){
				sleepH = (sleepH + 1) < 24 ? (sleepH + 1) : 00;
				sleepM = sleepM % 60;
			}
			drawDottedLine(footerLineX + 20, height - footerLineY, horLineHeight, formatHourM(sleepH, sleepM), sleepIcon, txtColor[1], ctx);
		}
		
		if(checkTreeCount == 0){
			//无数据的时候
			ctx.beginPath();
			ctx.font = "bolder 32px Helvetica";
			ctx.fillStyle = "#959595";
			ctx.textBaseline = "middle";
			ctx.textAlign = "center";
			ctx.fillText("亲，是不是忘了上传睡眠数据呢？", width / 2, height / 2);
			ctx.closePath();	

		}
		checkTreeCount = 0;
	}

}
//绘制竖向虚线
function drawDottedLine(_x,_y,_lineHeight,_text,_img,txtColor,ctx){
	//绘制虚线 图标 文字
	var hh = _lineHeight / 30;
	
	for(var j = 0; j < 30; j++){
		//绘制虚线
		if(j % 2 == 0){
			ctx.beginPath();
			ctx.strokeStyle = txtColor;
			ctx.lineWidth = 3;
			ctx.moveTo(_x - 1, _y - hh * j);
			ctx.lineTo(_x - 1, _y - hh * (j + 1));
			ctx.closePath();
			ctx.stroke();
		}
		//绘制图标加文字
		if(j == 29){
			//文字 时间
			ctx.beginPath();
			ctx.font = "bold 18px Helvetica";
			ctx.fillStyle = txtColor;
			ctx.textAlign = 'center';
			ctx.fillText(_text, _x + ctx.measureText(_text).width - 10, _y - hh * (j - 2));
			ctx.closePath();

			//图标
			ctx.drawImage(_img, _x  - 1 - 36 , _y - hh * (j - 2) - 18, 36, 36);
		}						
	}
}



//获取html请求路径的参数
function getParam(){
	var url = location.search; //获取url中"?"符后的字串
	var theRequest = new Object();
    var param=new Array();
  
   if (url.indexOf("?") != -1) {
     	var str = url.substr(1);
     	strs = str.split("&");
      	for(var i = 0; i < strs.length; i ++) {
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      	}
      
   	}
   	return theRequest;
}

/**
 * 监听横屏竖屏事件
 */
function banOrientation() {	
	if (window.orientation == 0 || window.orientation == 180) {// 竖屏
//		setTimeout(timeOutSetScale,300);

	}
	if (window.orientation == 90 || window.orientation == -90) {// 横屏

	}
	var dayOrWeek = document.getElementById("dayOrWeek").innerHTML;
	if (dayOrWeek == "天") {
		type = 0;
	} else {
		type = 1;
	}
//	setTimeout("timeOutSetScale()",300);
//	setTimeout("drawTreeC("+canvasW+", "+canvasH+","+ sleepDate+","+bgColor+","+type+")",500);
	timeOutSetScale();
	drawTreeC(canvasW, canvasH, sleepDate,bgColor,type);
};
//初始画布数据
var initData = {
		    "analysisDate": {
		        "date": 9,
		        "day": 4,
		        "hours": 8,
		        "minutes": 0,
		        "month": 9,
		        "seconds": 0,
		        "time": 1412812800000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "avgWeekDay": 0,
		    "awakeningCount": 0,
		    "code": "404",
		    "dataPrevious": true,
		    "daySetTsDate": {
		        "date": 8,
		        "day": 3,
		        "hours": 22,
		        "minutes": 0,
		        "month": 9,
		        "seconds": 0,
		        "time": 1412701200000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "daySetTwDate": {
		        "date": 9,
		        "day": 4,
		        "hours": 6,
		        "minutes": 0,
		        "month": 9,
		        "seconds": 0,
		        "time": 1412802000000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "deepSleepHoursM": 0,
		    "firstAnalysisDate": {
		        "date": 20,
		        "day": 6,
		        "hours": 8,
		        "minutes": 0,
		        "month": 8,
		        "seconds": 0,
		        "time": 1411171200000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "getupTime": null,
		    "memberId": "c91bd5ea75c740d8b34413b5ceedd7d7",
		    "memberSetTsDate": {
		        "date": 8,
		        "day": 3,
		        "hours": 23,
		        "minutes": 0,
		        "month": 9,
		        "seconds": 0,
		        "time": 1412780400000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "memberSetTwDate": {
		        "date": 9,
		        "day": 4,
		        "hours": 8,
		        "minutes": 0,
		        "month": 9,
		        "seconds": 0,
		        "time": 1412812800000,
		        "timezoneOffset": -480,
		        "year": 114
		    },
		    "message": "",
		    "shllowSleepHoursM": 0,
		    "sleepHoursM": 0,
		    "sleepQuality": "",
		    "sleepTime": null,
		    "weekSleep": 0,
		    "xLabels": "",
		    "yLabels": "",
		    "yValues": ""
		};

//显示元素
function showDOM(_id){
	document.getElementById(_id).style.display = "block";
}
//隐藏元素
function hiddenDOM(_id){
	document.getElementById(_id).style.display = "none";
}
